<template>
  <div class="shade" v-show="prop.isShowMyAssets" @click="closeMyAssets"></div>
  <div class="assets-dialog ground-glass" v-show="prop.isShowMyAssets">
    <div class="loding-container" v-if="loading">
      <div class="spinner"></div>
    </div>
    <div class="no-assest" v-else-if="assetsList.length == 0">
      无资产，如有资产，请及时联系信息部登记
    </div>
    <div class="assets-box" v-else>
      <div class="assets-item" v-for="item in assetsList">
        {{ item.zcbhx }}--{{ item.zcmc }}--{{ item.pp }}--{{ item.xh }}--{{
          item.lastname
        }}
        <p>{{ item.bz }}</p>
        <div class="line"></div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { watch, ref } from "vue";
import { getAssestList } from "@/api/index";
import { useStore } from "vuex";
const prop = defineProps({
  isShowMyAssets: {
    type: Boolean,
    default: false,
  },
});
const Store = useStore();
const loading = ref(true);
const assetsList = ref([]);
const emit = defineEmits(["closeMyAssets"]);
function closeMyAssets() {
  assetsList.value = [];
  loading.value = true;
  emit("closeMyAssets");
}
function getUserId() {
  return Store.state.userInfo.id;
}
function getMyAssest() {
  getAssestList({
    user_id: getUserId(),
    page: 1,
    size: 100,
  }).then(({ data: res }) => {
    if (res.code == 0) {
      assetsList.value = res.data.list.filter((item) => item.zcdl == 1);
    }
    loading.value = false;
  });
}
watch(
  () => prop.isShowMyAssets,
  (newV, oldV) => {
    if (newV) {
      getMyAssest();
    }
  }
);
</script>

<style scoped lang="less">
.assets-dialog {
  z-index: 10000;
  padding: 20px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: all 0.3s ease;
  width: 500px;
  .loding-container {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .no-assest {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 60px;
    font-weight: bolder;
    color: black;
  }
  .line {
    width: 100%;
    height: 2px;
    background-color: #0000004d;
    margin-bottom: 10px;
  }
  .assets-box {
    max-height: 600px;
    overflow-y: scroll;
    overflow-x: hidden;
    .assets-item {
      text-align: left;
      line-height: 32px;
      font-size: 20px;
      font-weight: 800;
      p {
        font-size: 14px;
        font-weight: 400;
      }
    }
  }
}
</style>
